package com.newbee.activity.tab;

import org.jivesoftware.smack.SmackAndroid;
import org.jivesoftware.smack.XMPPException;

import com.hhu.newbee.R;
import com.newbee.smack.SmackClient;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class PasswordFixActivity extends Activity implements OnClickListener
{

	private EditText mPwd;
	private EditText mReapeatPwd;

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.activity_fixpassowrd);
		initLayout();
	}

	private void initLayout()
	{

		mPwd = (EditText) findViewById(R.id.regInfoPwd);
		mReapeatPwd = (EditText) findViewById(R.id.regInfoPwdRepeat);
		this.findViewById(R.id.regInfoNextbtn).setOnClickListener(this);
	}

	@Override
	public void onClick(View v)
	{

		switch (v.getId())
		{
		case R.id.regInfoNextbtn:
		{
			String pwd = mPwd.getText().toString();
			String rpwd = mReapeatPwd.getText().toString();
			if (pwd.length() == 0 || rpwd.length() == 0
					|| pwd.equals(rpwd) == false)
			{
				Toast.makeText(this, "修改密码错误，请仔细检查输入的密码", Toast.LENGTH_LONG)
						.show();
			}
			else
			{
				try
				{
					SmackClient.connection.getAccountManager().changePassword(
							pwd);
					Toast.makeText(this, "修改密码成功！", Toast.LENGTH_LONG).show();
				}
				catch (XMPPException e)
				{
					e.printStackTrace();
					Toast.makeText(this, "密码修改失败！", Toast.LENGTH_LONG).show();

				}

			}

			break;
		}
		default:
			break;
		}

	}
}
